package com.xinzhi.service.impl;

import com.xinzhi.mapper.PoinosMapper;
import com.xinzhi.pojo.Poinos;
import com.xinzhi.pojo.Reason;
import com.xinzhi.service.PoinosService;
import com.xinzhi.utils.RedisUtils;
import com.xinzhi.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class PoinosServiceImpl  implements PoinosService {
    @Autowired
    private PoinosMapper poinosMapper;
    @Autowired
    private RedisUtils redisUtils;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * 特殊加分申请修改接口
     * @param add
     * @return
     */
    @Override
    public Result updateReason(Reason add) {
        if (add == null){
            return Result.error("该信息不存在");
        }
        redisTemplate.delete("add");
        int updatereason = poinosMapper.uapdateReason(add);
        try {
            Thread.sleep(800);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        redisTemplate.delete("add");
        Object o = redisUtils.get("add");
        return updatereason >0 ? Result.ok("修改成功") : Result.error("修改失败");

    }


    /**
     * 特殊扣分申请修改接口
     * @param poinos
     * @return
     */
    @Override
    public Result updatePoinos(Poinos poinos) {
        if (poinos == null) {
            return Result.error("该信息不存在");
        }
        redisTemplate.delete("poinos");
        int i1 = poinosMapper.updatePoints(poinos);
        try {
            Thread.sleep(800);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        redisTemplate.delete("poinos");
        Object o = redisUtils.get("poinos");
        return i1 > 0 ? Result.ok("修改成功") : Result.error("修改失败");
    }

}
